/*
 * Copyright (C) 2004, Velocityme Partnership
 * TaskTimeActionForm.java
 *
 * Created on 06 September 2004, 05:16
 */

package com.velocityme.www.actionforms;

import java.util.Calendar;
import java.util.Date;

import org.apache.struts.action.*;

/**
 *
 * @author  Robert
 */
public class TimeActionForm extends ActionForm {
    
    private int m_timeId;
    private String m_description;
    private int m_taskId;
    private int m_stateId;
    private byte m_percentageComplete;
    private int m_year;
    private int m_month;
    private int m_day;
    private int m_durationDays;
    private int m_durationHours;
    private int m_durationMins;
    private Time m_startTime = new Time();
    private Time m_stopTime = new Time();
    
    /** Creates a new instance of TaskTimeActionForm */
    public TimeActionForm() {
    }
    
    public int getTimeId() { return m_timeId; }
    
    public void setTimeId(int timeId) { m_timeId = timeId; }
    
    public String getDescription() { return m_description; }
    
    public void setDescription(String description) { m_description = description; }
    
    public byte getPercentageComplete() { return m_percentageComplete; }
    
    public void setPercentageComplete(byte percentageComplete) { m_percentageComplete = percentageComplete; }
    
    public int getTaskId() { return m_taskId; }
    
    public void setTaskId(int taskId) { m_taskId = taskId; }
    
    public int getStateId() { return m_stateId; }
    
    public void setStateId(int stateId) { m_stateId = stateId; }
    
    public int getYear() { return m_year; }
    
    public void setYear(int year) { m_year = year; }
    
    public int getMonth() { return m_month; }
    
    public void setMonth(int month) { m_month = month; }
    
    public int getDay() { return m_day; }
    
    public void setDay(int day) { m_day = day; }
    
    public int getStartHour() { return m_startTime.getHour(); }
    
    public void setStartHour(int startHour) { m_startTime.setHour(startHour); }
    
    public int getStartMinute() { return m_startTime.getMinute(); }
    
    public void setStartMinute(int startMinute) { m_startTime.setMinute(startMinute); }
    
    public int getStopHour() { return m_stopTime.getHour(); }
    
    public void setStopHour(int stopHour) { m_stopTime.setHour(stopHour); }
    
    public int getStopMinute() { return m_stopTime.getMinute(); }
    
    public void setStopMinute(int stopMinute) { m_stopTime.setMinute(stopMinute); }
    
    public int getDurationDays() { return m_durationDays; }
    
    public void setDurationDays(int durationDays) { m_durationDays = durationDays; }
    
    public int getDurationHours() { return m_durationHours; }
    
    public void setDurationHours(int durationHours) { m_durationHours = durationHours; }
    
    public int getDurationMins() { return m_durationMins; }
    
    public void setDurationMins(int durationMins) { m_durationMins = durationMins; }
    
    public int getDurationTotalMins() {
        return m_durationDays * 8 * 60 + m_durationHours * 60 + m_durationMins;
    }
    
    public void setDurationTotalMins(int totalMins) {
        m_durationDays = totalMins / (8 * 60);
        m_durationHours = (totalMins / 60) % 8;
        m_durationMins = totalMins % 60;
    }
    
    private class Time {
        private int m_hour;
        private int m_minute;
        
        public void setTime(Date date) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date);
            m_year = calendar.get(Calendar.YEAR);
            m_month = calendar.get(Calendar.MONTH);
            m_day = calendar.get(Calendar.DATE);
            m_hour = calendar.get(Calendar.HOUR_OF_DAY);
            m_minute = calendar.get(Calendar.MINUTE) / 5 * 5;
        }
        
        public Date getDate() {
            Calendar date = Calendar.getInstance();
            date.clear();
            date.set(m_year, m_month, m_day, m_hour, m_minute, 0);
            return date.getTime();
        }
        
        public int getHour() { return m_hour; }
        public void setHour(int hour) { m_hour = hour; }
        public int getMinute() { return m_minute; }
        public void setMinute(int minute) { m_minute = minute; }
    }
    
    public Date getStartDate() {
        return m_startTime.getDate();
    }
    
    public void setStartDate(Date start) {
        m_startTime.setTime(start);
    }
    
    public Date getStopDate() {
        return m_stopTime.getDate();
    }
    
    public void setStopDate(Date stop) {
        m_stopTime.setTime(stop);
    }
}
